<!--
 * @Date: 2023-04-04 09:39:47
 * @LastEditTime: 2023-04-07 09:16:47
-->
<template>
  <div>
    <a-dropdown placement="bottomRight">
      <span class="ant-pro-account-avatar" @click="(e) => e.preventDefault()">
        <a-avatar size="small" :src="avatar" class="antd-pro-global-header-index-avatar" />
        <span>{{ $store.getters.username }}</span>
      </span>
      <template v-slot:overlay>
        <a-menu class="ant-pro-drop-down menu" :selected-keys="[]">
          <a-menu-item key="changePW" @click="$refs.ChangePassword.open()">
            <a-icon type="lock" />
            修改密码
          </a-menu-item>
          <a-menu-item key="logout" @click="handleLogout">
            <a-icon type="logout" />
            注销登录
          </a-menu-item>
        </a-menu>
      </template>
    </a-dropdown>
    <change-password ref="ChangePassword"></change-password>
  </div>
</template>

<script>
import { Modal } from 'ant-design-vue'
import { mapActions } from 'vuex'
import ChangePassword from '@/views/user/updatePassword.vue'

export default {
  name: 'AvatarDropdown',
  props: {},
  components: {
    ChangePassword
  },
  data () {
    return {
      avatar: require('@/assets/icons/user-avatat.png')
    }
  },
  methods: {
    ...mapActions(['Logout']),
    handleLogout (e) {
      Modal.confirm({
        title: '系统提示',
        content: '确定要退出登录吗',
        onOk: () => {
          this.Logout().then(() => {
            this.$message.success('注销成功')
            this.$router.push({
              path: '/user/login'
            })
          })
        },
        onCancel () {}
      })
    }
  }
}
</script>

<style lang="less" scoped>
.ant-pro-drop-down {
  :deep(.action) {
    margin-right: 8px;
  }
  :deep(.ant-dropdown-menu-item) {
    min-width: 160px;
  }
}
</style>
